package com.framework.modules.live.controller;

import com.framework.common.utils.PageUtils;
import com.framework.common.utils.R;
import com.framework.common.validator.ValidatorUtils;
import com.framework.modules.live.entity.LiveHistoryEntity;
import com.framework.modules.live.service.LiveHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 *  
 *
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2021-01-04 03:13:24
 */
@RestController
@RequestMapping("live/livehistory")
@Api(tags = "LiveHistoryController")
public class LiveHistoryController {
    @Autowired
    private LiveHistoryService liveHistoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
        @RequiresPermissions("live:livehistory:list")
        @ApiOperation("list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = liveHistoryService.queryLiveHistory(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
        @RequiresPermissions("live:livehistory:info")
        @ApiOperation("info")
    public R info(@PathVariable("id") Integer id){
        LiveHistoryEntity liveHistory = liveHistoryService.selectById(id);

        return R.ok().put("liveHistory", liveHistory);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
        @RequiresPermissions("live:livehistory:save")
        @ApiOperation("save")
    public R save(@RequestBody LiveHistoryEntity liveHistory){
        liveHistoryService.insert(liveHistory);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
        @RequiresPermissions("live:livehistory:update")
        @ApiOperation("update")
    public R update(@RequestBody LiveHistoryEntity liveHistory){
        ValidatorUtils.validateEntity(liveHistory);
        liveHistoryService.updateAllColumnById(liveHistory);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
        @RequiresPermissions("live:livehistory:delete")
        @ApiOperation("delete")
    public R delete(@RequestBody Integer[] ids){
        liveHistoryService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
